// pages/waitmassage/waitmassage.js
const { getAllUnDealMaintenanceList, operateGetUnDeal } = require("../../utils/api");
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    myTitle:"待回复",
    isPoup:false,
    navBarHeight:app.globalData.navBarHeight,
    allUnDealMaintenanceList: [],
    userInfo: null,
    search: {
      value: ''
    },
  },
 
  onLoad(options) {
    this.setData({
      userInfo: wx.getStorageSync('userInfo')
    })
    this.operateGetUnDeal();
  },
  handelback(){
    wx.navigateBack({
      delta:1
    })
  },

  goDetail(e) {
    wx.navigateTo({
      url: `/pages/detail/detail?sourceNavigate=waitmassage&maintenanceNumber=${e.currentTarget.dataset.maintenancenumber}`,
    });
  },

  operateGetUnDeal(){
    const data = { PhoneNumber: this.data.userInfo.PhoneNumber, };
    operateGetUnDeal(data).then(res => { 
      if (res.code === 4002130) {
        const result = res.data.map(item => {
          return {
            ...item,
            hidden: false
          }
        })
        this.setData({
          allUnDealMaintenanceList : res.data,
        });
      }
    });
  },

  
  searchBarOnChange(e) {
    this.setData({
      'search.value': e.detail,
    });
  },
  
  searchBarOnSearch() {
    const text = this.data.search.value; // 获取搜索框的值
    const allUnDealMaintenanceList = this.data.allUnDealMaintenanceList;
  
    // 遍历数组并根据条件设置 hidden 属性
    allUnDealMaintenanceList.forEach(item => {
      if (text === '') {
        // 如果搜索框为空，显示所有项
        item.hidden = false;
      } else {
        // 如果 BatteryUnite 存在且包含搜索文本，则显示该项
        if (item.BatteryUnite && item.BatteryUnite.includes(text)) {
          item.hidden = false;
        } else {
          item.hidden = true;
        }
      }
    });
      
    // 更新数据到页面
    this.setData({
      allUnDealMaintenanceList: allUnDealMaintenanceList
    });
  
    console.log(allUnDealMaintenanceList); // 打印结果以验证
  },
})